<template>
	<view class="content font_family" v-if="detail">
		<view class="wl_msg" style="margin-bottom: 30rpx;">
			<u-steps :current="steps_num2(detail.status)" activeColor='#FF3767' v-if="detail.order_type==3">
				<u-steps-item :title="item" v-for="(item,index) in steps_df" :key="index">
				</u-steps-item>
			</u-steps>
			<u-steps :current="steps_num(detail.status)" activeColor='#FF3767' v-else>
				<u-steps-item :title="item" v-for="(item,index) in steps" :key="index">
				</u-steps-item>
			</u-steps>
		</view>
		<view class="wl_msg" v-if="detail.order_type==2">
			<view class="wl_date f_z_b" v-if="detail.status==4 || detail.status==5"
				@click="go(`/pages/order/wl_map?id=${detail.order_no}`)">
				<view class="left" v-if="detail.status==4">
					<view class="title">
						预计{{detail.yjfh_time_zh}}发货 {{detail.yjsd_time_zh}}到达
					</view>
					<view class="text">
						快递运输|预计{{detail.yjfh_time_zh}}发货，{{detail.yjsd_time_zh}}到达
					</view>
				</view>
				<view class="left qs" v-if="detail.status==5">
					商品已签收
				</view>
				<view class="right">
					<image src="../../static/public/go.png" mode=""></image>
				</view>
			</view>
			<view class="sh_msg">
				<view class="top">
					<text>{{detail.address_json.name}}</text>
					<text style="margin-left: 10rpx;">{{detail.address_json.tel}}</text>
				</view>
				<view class="bottom">
					地址：{{detail.address_json.address+detail.address_json.xx_address}}
				</view>
			</view>
		</view>
		<view class="wl_msg f_j" v-else-if="detail.order_type==1" @click="zt_d">
			<view class="sh_msg" style="flex: 1;">
				<view class="top">
					<text>预约自提时间：</text>
					<text style="margin-left: 10rpx;">{{detail.yy_time}}</text>
				</view>
				<view class="bottom">
					自提点：{{detail.store.address}}
				</view>
			</view>
			<image style="width: 36rpx;height: 36rpx;margin-left: 15rpx;" src="../../static/index/go_dl.png" mode="">
			</image>
		</view>
		<view class="wl_msg f_j" v-else>
			<view class="sh_msg" style="flex: 1;">
				<view class="top">
					<text>货到付款</text>
				</view>
				<view class="bottom">
					本订单为货到付款，请收到货物确认无误后再进行付款
				</view>
			</view>
			<!-- <image style="width: 36rpx;height: 36rpx;margin-left: 15rpx;" src="../../static/index/go_dl.png" mode="">
			</image> -->
		</view>
		<view class="sp_msg">
			<view class="item f_d" v-for="(item,index) in detail.detail" :key="index">
				<view class="f">
					<image :src="item.goods_image" mode="aspectFill"></image>
					<view class="msg f_d f_z_b">
						<view class="title text_ellipsis2">
							{{item.goods_title}}
						</view>
						<view class="gg">
							规格:{{item.item_name}}
						</view>
						<view class="time" v-if="detail.order_type==2">
							发货时间：{{detail.ps_time}}
						</view>
					</view>
					<view class="price f_d">
						<view class="text">
							￥{{item.goods_price}}
						</view>
						<view class="num">
							x{{item.goods_count}}
						</view>
						<view v-if="detail.status==5 && item.is_common===0 && item.refund==0" class="pl_btn"
							@click.stop="go(`/pages/order/pl_sub?id=${item.id}`)">
							商品评价
						</view>
						<view v-if="item.refund==-1" class="pl_btn" @click.stop="qx_tk(item.id)">
							取消退款
						</view>
					</view>
				</view>
				<view class="jh_sp" v-if="item.refund_type!=2 && item.refund_type!=0"
					@click.stop="jh(item.id,detail.store)">
					寄回商品
				</view>
			</view>
			<view class="sfk f_z_b f_j" v-if="detail.coupon_title">
				<view class="left">
					优惠券
				</view>
				<view class="right">
					<text>{{detail.coupon_title}}</text>
				</view>
			</view>
			<view class="sfk f_z_b f_j" v-if="detail.used_amount!=0">
				<view class="left">
					优惠券抵扣
				</view>
				<view class="right">
					<text style="color: #FF3767;">￥{{detail.used_amount}}</text>
				</view>
			</view>
			<view class="sfk f_z_b f_j">
				<view class="left">
					实付款
				</view>
				<view class="right">
					<text>共计</text>
					<text class="price">￥{{detail.order_amount_total}}</text>
				</view>
			</view>
			<view class="order_id f_z_b">
				<view class="left">
					订单编号
				</view>
				<view class="right">
					<text>{{detail.order_no}}</text>
					<text class="copy" @click="copy(detail.order_no)">复制</text>
				</view>
			</view>
			<view class="order_id f_z_b">
				<view class="left">
					配送方式
				</view>
				<view class="right">
					<text class="copy">{{detail.order_type | orderType}}</text>
				</view>
			</view>
			<!-- <view class="all f_zj">
				<text>全部订单信息</text>
				<image src="../../static/public/xl.png" mode=""></image>
			</view> -->
		</view>
		<view class="btn_box f">
			<!-- <view class="btn" @click="lj_pay" v-if="detail.status==1">
				立即支付
			</view> -->
			<!-- <view class="btn" @click="go_pl(detail)" v-if="detail.status==5">
				商品评价
			</view> -->
			<view class="btn" @click="tk"
				v-if="(detail.status==2 || detail.status==4 ||detail.status==5) && detail.sl_c>0 && detail.order_type!=3">
				申请售后
			</view>
			<!-- <view class="btn" @click="qx_tk" v-if="detail.status==3 && detail.refund_status==0">
				取消退款
			</view> -->
		</view>
		<view class="zf_btn f_zj" @click="lj_pay" v-if="detail.status==1 && detail.order_type!=3">
			立即支付
		</view>
	</view>
</template>

<script>
	import mixin from '@/mixins/pay.js'
	import { mapState } from 'vuex'
	import { order_detail, cancel_refund } from '@/api/user.js'
	export default {
		mixins: [mixin],
		computed: {
			...mapState(['dl_id', 'common', 'user_info'])
		},
		data() {
			return {
				query_data: {
					dl: '',
					order_id: ''
				},
				detail: '',
				steps: ['待付款', '配货中', '已发货', '已完成', '已取消'],
				steps_df: ['配货中', '已发货', '已完成', '已取消'],
				steps_current: 0
			}
		},
		onShow() {
			this.get_detail()
		},
		onLoad(e) {
			this.query_data.order_id = e.id
			// this.query_data.dl = this.dl_id
			this.get_detail()
		},
		methods: {
			get_detail() {
				order_detail(this.query_data).then(res => {
					if (res.code == 1) {
						this.detail = res.data
					}
				})
			},
			lj_pay() {
				if (this.user_info.openid) {
					this.pay(this.detail.order_no, this.user_info.openid, this.detail.dl_id)
				} else {
					this.get_openid(this.detail.order_no, this.detail.dl_id)
				}
			},
			go_pl(detail) {
				console.log(detail)
			},
			tk() {
				let sp = JSON.stringify(this.detail.detail)
				// this.go(`/pages/order/tk_check?msg=${sp}&status=${this.detail.status}&order=${this.detail.order_no}`)
				this.go(`/pages/order/tk_detail?msg=${sp}&status=${this.detail.status}&order=${this.detail.order_no}`)
			},
			qx_tk(id) {
				uni.showModal({
					title: '提示',
					content: '是否取消退款？',
					success: (res) => {
						if (res.confirm) {
							cancel_refund({ order_detail_id: id }).then(res => {
								if (res.code == 1) {
									this.back()
								} else {
									uni.showToast({
										icon: 'none',
										title: res.msg
									})
								}
							})
						} else if (res.cancel) {}
					}
				});
			},
			zt_d() {
				uni.openLocation({
					latitude: Number(this.detail.store.latitude),
					longitude: Number(this.detail.store.longitude)
				})
			},
			// 步骤条
			steps_num(val) {
				if (val == 1) {
					return 0
				} else if (val == 2) {
					return 1
				} else if (val == 4) {
					return 2
				} else if (val == 5) {
					return 3
				} else {
					return 4
				}
			},
			steps_num2(val) {
				if (val == 2) {
					return 0
				} else if (val == 4) {
					return 1
				} else if (val == 5) {
					return 2
				} else {
					return 3
				}
			},
			// 寄回商品
			jh(id, detail) {
				let obj = {
					name: detail.name,
					tel: detail.tel,
					address: detail.address,
					xx_address: detail.address_detail
				}
				let msg = JSON.stringify(obj)
				this.go(`/pages/order/jh_sp?id=${id}&msg=${msg}`)
			}
		},
		filters: {
			orderType(val) {
				if (val == 1) {
					return '自提'
				} else if (val == 2) {
					return '配送'
				} else if (val == 3) {
					return '货到付款'
				}
			},
		},
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 30rpx;
		background-color: #F8F9FC;

		.wl_msg {
			padding: 30rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;

			.wl_date {
				margin-bottom: 20rpx;

				.left {
					.title {
						font-weight: 250;
						font-size: 32rpx;
						color: #232323;
					}

					.text {
						margin-top: 10rpx;
						font-weight: 250;
						font-size: 24rpx;
						color: #999999;
					}
				}

				.qs {
					font-weight: 400;
					font-size: 28rpx;
					color: #333333;
				}

				.right {
					image {
						width: 30rpx;
						height: 30rpx;
					}
				}
			}

			.sh_msg {

				.top {
					font-weight: 250;
					font-size: 24rpx;
					color: #232323;
				}

				.bottom {
					margin-top: 10rpx;
					font-weight: 250;
					font-size: 24rpx;
					color: #999999;
				}
			}
		}

		.sp_msg {
			margin-top: 30rpx;
			padding: 30rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;

			.item {
				margin-bottom: 20rpx;

				image {
					width: 166rpx;
					height: 176rpx;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
				}

				.msg {
					margin-left: 15rpx;
					flex: 1;

					.title {
						font-weight: 400;
						font-size: 28rpx;
						color: #232323;
					}

					.gg {
						font-weight: 400;
						font-size: 24rpx;
						color: #666666;
					}

					.time {
						font-weight: 400;
						font-size: 26rpx;
						color: #FF9922;
					}
				}

				.price {
					margin-left: 20rpx;
					font-weight: 400;
					font-size: 26rpx;
					color: #666666;
					align-items: flex-end;

					.num {
						margin-top: 10rpx;
						// align-self: flex-end;
					}

					.pl_btn {
						margin-top: auto;
						padding: 6rpx 15rpx;
						color: #FFFFFF;
						border-radius: 1000rpx;
						background-color: #FF3767;
					}
				}

				.jh_sp {
					margin-top: 20rpx;
					align-self: flex-end;
					padding: 6rpx 15rpx;
					color: #FF3767;
					font-size: 26rpx;
					border-radius: 1000rpx;
					border: 2rpx solid #FF3767;
				}
			}

			.sfk {
				margin-top: 30rpx;

				.left {
					font-weight: 250;
					font-size: 28rpx;
					color: #666666;
				}

				.right {
					font-weight: 250;
					font-size: 24rpx;
					color: #232323;

					.price {
						margin-left: 10rpx;
						font-weight: 400;
						font-size: 40rpx;
						color: #FF3767;
					}
				}
			}

			.order_id {
				margin-top: 40rpx;

				.left {
					font-weight: 250;
					font-size: 28rpx;
					color: #666666;
				}

				.right {
					font-weight: 400;
					font-size: 28rpx;
					color: #232323;

					.copy {
						margin-left: 20rpx;
						font-weight: 250;
						font-size: 28rpx;
						color: #232323;
					}
				}
			}

			.all {
				margin-top: 30rpx;
				font-weight: 250;
				font-size: 28rpx;
				color: #999999;

				image {
					margin-left: 15rpx;
					width: 30rpx;
					height: 30rpx;
				}
			}
		}

		.btn_box {
			margin-top: 30rpx;
			justify-content: flex-end;

			.btn {
				margin-left: 46rpx;
				border-radius: 32rpx 32rpx 32rpx 32rpx;
				border: 2rpx solid #232323;
				font-weight: 250;
				font-size: 24rpx;
				color: #232323;
				padding: 18rpx 32rpx;
			}
		}

		.zf_btn {
			margin-top: 30rpx;
			height: 81rpx;
			background: #EE4133;
			border-radius: 47rpx 47rpx 47rpx 47rpx;
			font-weight: 400;
			font-size: 30rpx;
			color: #FFFFFF;
		}
	}
</style>